// @import
import HeroCtrl, { g_oHeroCtrlMap } from "../../ctrl/HeroCtrl";
import { g_oCmdHandlerMap } from "../ICmdHandler";

// @import
import mod_gameMsgProtocol = require("../../msg/mod_gameMsgProtocol");

/**
 * 用户减血结果处理器
 */
export default class UserSubtractHpResultHandler {
    /**
     * 处理结果
     * 
     * @param oResult 结果
     * @returns
     */
    handle(oResult: mod_gameMsgProtocol.msg.UserSubtractHpResult): void {
        if (null == oResult) {
            return;
        }

        let oHeroCtrl: HeroCtrl = g_oHeroCtrlMap.get(oResult.targetUserId);

        if (null != oHeroCtrl) {
            oHeroCtrl.doDamage(oResult.subtractHp);
        }
    }
}

// @autoExec
(function() {
    console.log("注册 -- UserSubtractHpResultHandler");
    g_oCmdHandlerMap.set(
        mod_gameMsgProtocol.msg.MsgCode.USER_SUBTRACT_HP_RESULT, 
        new UserSubtractHpResultHandler()
    );
})();
